<?php

class Emms_Form_Loan_Business extends HTech_Form
{
    protected $_primary  = 'LoanId';
    
    public function getValues()
    {
        $data = parent::getValues();
        //$data['Date'] = date('Y-m-d');     
        //unset($data['LastEditUserId']);
        //unset($data['LastEditDate']);
        return $data;
    }
    
    public function __construct($loan) 
    {
        parent::__construct();
        
        
        $this->setName('SelectBusiness');
        
        $loanId = new Zend_Form_Element_Hidden('LoanId');
        
        $businesses = new Businesses();
        $select = $businesses->select();
        $select->where('ClientId = ?', $loan->ClientId);
        $rows = $businesses->fetchAll($select);
        
        $businessId = new Zend_Form_Element_Radio("BusinessId");            
        $businessId->setRequired(true)                
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->setLabel("Registered businesses");
        foreach($rows as $business)
            $businessId->addMultiOption($business->BusinessId, $business->Name);
                                
        $submit = new Zend_Form_Element_Submit('Submit');
        $submit->setLabel("Submit")
            ->addDecorator(new HTech_Form_Decorator_Button(array('type' => 'submit')));        
        
        $this->addElements(array($businessId, $submit, $loanId));
        
        $this->setDefaults(array('LoanId' => $loan->LoanId));
    }

}